package com.auto.survey.activity.config

import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

class ViewPagerAdapter  : RecyclerView.Adapter<ViewPagerAdapter.ViewHolder>(){

    // 存储所有页面的View列表
    private val views = mutableListOf<View>()

    @SuppressLint("NotifyDataSetChanged")
    fun setViews(datas:MutableList<View>) {
        views.clear()
        views.addAll(datas)
        notifyDataSetChanged()
    }

    // 添加视图到适配器
    fun addView(view: View) {
        views.add(view)
        notifyItemInserted(views.size - 1)
    }

    // 创建ViewHolder
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(views[viewType])
    }
    // 绑定ViewHolder
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        // 无需额外操作，视图已在ViewHolder中设置
    }

    // 返回视图类型（这里直接使用position作为类型）
    override fun getItemViewType(position: Int): Int = position

    // 返回页面总数
    override fun getItemCount(): Int = views.size

    // ViewHolder类
    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}